// pages/login/login.js
const $api = require("../../api/login").API
const $mine = require("../../api/mine").API
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    phone:'18746610607',
    pass:'123456'
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //获取账号
    tel(e){
      var t = this
      t.setData({
        phone:e.detail.value
      })
    },
    //获取密码
    pass(e){
      console.log(123)
      var t = this
      t.setData({
        pass:e.detail.value
      })
    },
    login:function(){
      var t = this,
      phone = t.data.phone,
      pass = t.data.pass,
      data = {
        'app_type':'android',
        'member_mobile':phone,
        'member_pass':pass,
        'member_type':2,
        'os_type':'android'
      }
      if(phone==''|| pass==''){
        wx.showToast({
          title: '请填写账号密码',
        })
      }else{
        $api.login(data).then(res => {
          // console.log(res)  //res即是请求到的数据
          if(res.status==200){
            wx.setStorageSync('user', res.data)
            //获取孩子列表
            var m = {'member_id':res.data.member_id}
            $api.getChildList(m).then(re=>{
              // console.log(re)
              // 将所有孩子列表存到缓存
              wx.setStorageSync('child', re.data)
              wx.setStorageSync('child_one', re.data[0])
              t.getClass()
<<<<<<< HEAD
            })
           
=======
            })
            wx.showToast({
              title: '登录成功',
            })
            
            setTimeout(function(){
              wx.switchTab({
                url: '/pages/index/index'
              })  
            },2000)
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
          }
        })
      } 
    },
    //获取对接孩子的班级
    getClass() {
      var t= this,
      data = {
        child_id:wx.getStorageSync('child_one').child_id,
      }
      $mine.getClass(data).then(res=>{
<<<<<<< HEAD
        console.log(res)
        wx.setStorageSync("classinfo",res.data[0])
        wx.showToast({
          title: '登录成功',
        })
        setTimeout(
          function () {
            wx.switchTab({
              url: '/pages/index/index'
            })  
           }, 
          2000) 
        
      })

=======
      console.log(res)
      wx.setStorageSync("classinfo",res.data[0])
      })
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
    },
  },
  
})
